<?php
namespace Swiftx\Tools;
use Swiftx\Http\IRequest;
use Swiftx\System\Object;
use Swiftx\Tools;
/**
 * 调试工具类
 * @author		Hismer <odaytudio@gmail.com>
 * @since		2015-11-04
 * @copyright	Copyright (c) 2014-2015 Swiftx Inc.
 */
class Debug {

    /** @var null|string 输出文件  */
    protected static $LogFile = null;
    /** @var null|IRequest 用户请求 */
    protected static $Request = null;

    /**
     * 开启并配置程序调试工具
     * @param string $file
     * @param IRequest $request
     */
    public static function Init($file, $request=null){
        static::$LogFile = $file;
        static::$Request = $request;
        if($request == null)
            file_put_contents (static::$LogFile, date('Y-m-d H:i:s')." : Script \r\n",FILE_APPEND);
        else if($request->UserAgent != null)
            file_put_contents (static::$LogFile, date('Y-m-d H:i:s').' : '.static::$Request->Url."\r\n",FILE_APPEND);
        else file_put_contents (static::$LogFile, date('Y-m-d H:i:s')." : Script \r\n",FILE_APPEND);
    }

    /**
     * Debug调试日志输出
     * @param $message
     */
    public static function Out($message){
        if(static::$LogFile!=null)
            file_put_contents (static::$LogFile, $message."\r\n", FILE_APPEND);
    }

    /**
     * 打印数组到日志
     * @param array $array
     */
    public static function PrintArray(array $array){
        static::Out(print_r($array,true));
    }

    public static function PrintObject($object){
        static::Out(var_dump($object,true));
    }


}